<?php
class Mobile_GameController extends  Zgome_Controller{
	public function init(){
		parent::init();
	}
	public function detailAction(){
		$this->view->headScript()->offsetSetFile("4",$this->view->baseUrl(). "/public/common/js/jquery.easing.1.2.js","text/javascript");
		$this->view->headScript()->offsetSetFile("2",$this->view->baseUrl(). "/public/common/js/jquery.movingboxes.js","text/javascript");
		$this->view->headScript()->offsetSetFile("3",$this->view->baseUrl(). "/public/common/js/jquery.movingboxes.min.js","text/javascript");
		$this->view->headLink()->appendStylesheet($this->view->baseUrl(). "/public/common/css/movingboxes-ie.css");
		$this->view->headLink()->appendStylesheet($this->view->baseUrl(). "/public/common/css/movingboxes.css");
		$gameId =$this->_request->getParam("gameId");
		if($gameId!=null){
			$gameModel = new Model_Game();
			$this->view->game = $gameModel->getGameById($gameId);
			if($this->view->game ==null){
				$this->_redirect("/mobile");
			}
			$this->view->game =$this->view->game[0];
			$this->view->gameLists = $gameModel->listall();
			$this->view->install_file_size = round(filesize("public/common/game/".$this->view->game['install_file'])/1024/1024, 1);
			$this->view->url = $this->getRequest()->getRequestUri();
			$this->view->images = $gameModel->getGameImageById($gameId);
		}
		else{
			$this->_redirect("/mobile");
		}
	}
	public function gameAction(){
		$filter =$this->_request->getParam("filter");
		$this->view->filter = $filter;
		$game_model = new Model_Game();
		switch ($filter){
			case '1': //hot nhat
				$paginator = Zend_Paginator::factory($game_model->getHotGame());
		    	$paginator->setItemCountPerPage(10);
		    	$paginator->setCurrentPageNumber($this->_request->getParam("page",1));
		    	$this->view->gameLists = $paginator;
				break;
			case '2': //moi nhất
				$paginator = Zend_Paginator::factory($game_model->getNewGame());
		    	$paginator->setItemCountPerPage(2);
		    	$paginator->setCurrentPageNumber($this->_request->getParam("page",1));
		    	$this->view->gameLists = $paginator;
				break;
			default:
				$this->_redirect("mobile/index/index");
				break;
		}
	}
	public function  likeAction(){
		$this->_helper->layout()->disableLayout();
		$ns = new Zend_Session_Namespace("liked");
		if(isset($ns->liked)){
			echo "liked";
			return;
		} 
		if($this->_request->isPost()){
			$gameId = $this->_request->getPost('gameId');
			if($gameId){
				$ns->liked = "1";
				$mode_game = new Model_Game();
				$returnVal = $mode_game->addLike($gameId);
			}
		}
	}
	public function  shareAction(){
		$this->_helper->viewRenderer->setNoRender(true);
		if($this->_request->isPost()){
			$gameId = $this->_request->getPost('gameId');
			if($gameId){
				$mode_game = new Model_Game();
				$returnVal = $mode_game->addShare($gameId);
			}
		}
	}
	public function adddownloadAction(){
		$this->_helper->viewRenderer->setNoRender(true);
		if($this->_request->isPost()){
			$gameId = $this->_request->getPost('gameId');
			if($gameId){
				$mode_game = new Model_Game();
				$returnVal = $mode_game->addDownload($gameId);
			}
		}
	}
}